package com.kg.fiber.web;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ivan.toolkit.common.Aniout;
import com.kg.fiber.service.security.SecurityConfig;

@Controller
@RequestMapping("/security")
@ResponseBody
public class SecurityController {
	
	@RequestMapping(value = "/modify.do")
	public Aniout password(HttpSession session, String oldPassword, String newPassword, String newPassword2) {
			
		if(!newPassword.equals(newPassword2)) {
			return Aniout.failure().message("新密码确认不一致！");
		}
		
		SecurityConfig config =  SecurityConfig.instance.get();
		
		if(!config.checkPassword(oldPassword)) {
			return Aniout.failure().message("旧密码不正确！");
		}
		
		config.setNewPassword(newPassword);
		
		try {
			
			SecurityConfig.instance.set();
			return Aniout.success();
			
		} catch (Exception e) {

			return Aniout.failure().message(e.getMessage());	
		}
		
	}
		
}
